package com.sunagy.demand.backend.controller;

import com.sunagy.demand.backend.VO.ResultVO;
import com.sunagy.demand.backend.VO.request.CustomerProgressAddRequestVO;
import com.sunagy.demand.backend.VO.response.CustomerProgressResponseVO;
import com.sunagy.demand.backend.service.CustomerProgressService;
import com.sunagy.demand.backend.utils.ResultVOUtil;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * desc：用户需求进程接口
 * author：三餘無夢生
 * date：2018/4/11
 * time：下午4:10
 */
@Slf4j
@RestController
@RequestMapping("/customerProgress")
@Api(value = "管理端需求进程", description = "需求互动过程中相关接口")
public class CustomerProgressController {

    @Autowired
    private CustomerProgressService customerProgressService;

    @ApiOperation(value = "查询所有的需求进程", notes = "所有的需求进程，如果没有进程自动创建一个通用进程")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "", method = RequestMethod.GET)
    public ResultVO<List<CustomerProgressResponseVO>> getAll() {
        List<CustomerProgressResponseVO> customerProgressResponseVOList = customerProgressService.getAll();
        return ResultVOUtil.success(customerProgressResponseVOList);
    }

    @ApiOperation(value = "查询用户的需求进程", notes = "根据所有的需求进程，如果没有进程自动创建一个通用进程")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ResultVO<List<CustomerProgressResponseVO>> getListByCustomerId(@PathVariable("id") Integer customerId) {
        List<CustomerProgressResponseVO> customerProgressResponseVOList = customerProgressService.getEnableListByCustomerId(customerId);
        return ResultVOUtil.success(customerProgressResponseVOList);
    }

    @ApiOperation(value = "新增一个用户的需求进程", notes = "新增一个进程需求")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "/",method = RequestMethod.POST)
    public ResultVO<CustomerProgressResponseVO> add(@RequestBody CustomerProgressAddRequestVO customerProgressAddRequestVO){
        CustomerProgressResponseVO customerProgressResponseVO = customerProgressService.add(customerProgressAddRequestVO);
        return ResultVOUtil.success(customerProgressResponseVO);
    }

    @ApiOperation(value = "更改用户进程状态", notes = "更改用户进程状态")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "/changeStatus/{id}",method = RequestMethod.PUT)
    public ResultVO<CustomerProgressResponseVO> changeStatus(@PathVariable Integer id){
        CustomerProgressResponseVO customerProgressResponseVO = customerProgressService.changeStatus(id);
        return ResultVOUtil.success(customerProgressResponseVO);
    }

    @ApiOperation(value = "删除用户进程", notes = "根据id删除用户进程")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public ResultVO<CustomerProgressResponseVO> delete(@PathVariable Integer id){
        CustomerProgressResponseVO customerProgressResponseVO = customerProgressService.deleteById(id);
        return ResultVOUtil.success(customerProgressResponseVO);
    }

    @ApiOperation(value = "设置用户进程计划处理时间", notes = "设置用户进程计划处理时间")
    @ApiResponses({
            @ApiResponse(code = 500, message = "接口异常")
    })
    @RequestMapping(value = "/setDealTime/{id}",method = RequestMethod.PUT)
    public ResultVO<CustomerProgressResponseVO> setDealTime(@PathVariable Integer id, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")@RequestBody Date date){

        CustomerProgressResponseVO customerProgressResponseVO = customerProgressService.setDealTime(id,date);
        return ResultVOUtil.success(customerProgressResponseVO);
    }
}
